const fp = require('lodash/fp')
// 数据
// horsepower 马力, dollar_value 价格, in_stock 库存
const cars = [
    {
        name: 'Ferrari FF',
        horsepower: 660,
        dollar_value: 700000,
        in_stock: true
    },
    {
        name: 'Spyker C12 Zagato',
        horsepower: 650,
        dollar_value: 648000,
        in_stock: false
    },
    {
        name: 'Jaguar XKR-S',
        horsepower: 550,
        dollar_value: 132000,
        in_stock: false
    },
    {
        name: 'Audi R8',
        horsepower: 625,
        dollar_value: 114200,
        in_stock: false
    },
    {
        name: 'Aston Martin One-7',
        horsepower: 750,
        dollar_value: 1850000,
        in_stock: true
    },
    {
        name: 'Pagani Huayara',
        horsepower: 700,
        dollar_value: 1300000,
        in_stock: true
    }
]

// 练习4：使用flowRight写一个sanitizeNames()函数，返回一个下划线连接的小写字符串，把数组中的name转换为这种形式：例如：sanitizeNames(['Hello World']) => ["hello_world"]
// 把非字母数字替换为下划线
let _underscore = fp.replace(/\W+/g, '_') // <- 无需改动，并在sanitizeNames中使用 */    

// const sanitizeNames = fp.flowRight(fp.map(name => fp.toLower(name)), fp.map(name => name.replace(/\s+/g, "_")), fp.map(car => car.name));
const sanitizeNames = fp.map(fp.flowRight(
    name => fp.toLower(name),
    _underscore,
    car => car.name
))

console.log(sanitizeNames(cars));